package com.usian.article.controller;

import com.usian.api.article.ApArticleApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.dtos.ArticleDto;
import com.usian.model.article.dtos.ArticleHomeDto;
import com.usian.model.article.dtos.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleApi {

    @Autowired
    ApArticleService apArticleService;

    /**
     * admin 远程调用保存文章主表
     * @param apArticle
     * @return
     */
    @RequestMapping("/saveArticle")
    @Override
    public ApArticle saveArticle(@RequestBody ApArticle apArticle) {
        return apArticleService.saveArticle(apArticle);
    }

    /**
     * 文章默认查询列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @Override
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load((short)1,dto);
    }

    /**
     *文章默认查询列表  上拉加载更多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    @Override
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load((short)1,dto);
    }

    /**
     *文章默认查询列表  下拉加载最新
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    @Override
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load((short)2,dto);
    }

    /**
     * app 端文章查询详情
     * @param dto
     * @return
     */
    @PostMapping("/load_article_info")
    @Override
    public ResponseResult loadArticleInfo(@RequestBody ArticleDto dto) {
        return apArticleService.loadArticleInfo(dto);
    }

    /**
     * 查询文章关系接口
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    @Override
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleBehavior(dto);
    }

    /**
     * search 远程调用发布后的文章
     * @return
     */
    @PostMapping("/findArticleList")
    @Override
    public List<ApArticle> findArticleList() {
        return apArticleService.list();
    }
}
